<?php
/**
 * Created by PhpStorm.
 * User: lengbin
 * Date: 2018/6/21
 * Time: 上午11:10
 */


namespace common\core\actions;

use common\core\base\Action;
use yii\web\Response;

/**
 * list
 *
 * Class IndexAction
 * @package common\core\actions
 */
class IndexAction extends Action
{

    public $view = 'index';

    public function init()
    {
        $params = \Yii::$app->request->get();

        if ($this->params === null) {
            $this->params = $params;
        }

        if ($this->params instanceof \Closure) {
            $this->params = call_user_func($this->params, $params);
        }

        parent::init();
    }

    public function run()
    {
        if (\Yii::$app->request->isAjax) {
            \Yii::$app->response->format = Response::FORMAT_JSON;
            return $this->params;
        }
        return $this->controller->render($this->view, $this->params);
    }

}